<template>
	<view class="brand-list">
		<scroll-view scroll-x class="select" :rebound="false" :show-scrollbar="false">
			<view class="flex select-content">
				<view @click="chooseBrand(-1, -1)">
					<view class="select-list flex" :style="{border: current === -1?'1rpx solid #000000;':''}" style="margin: 0;">
						<text>全部品牌</text>
					</view>
				</view>
				<view v-for="(item, index) in list" :key="item.id" @click="chooseBrand(index,item.id)">
					<view class="select-list flex" :style="{border: current === index?'1rpx solid #000000;':''}">
						<text>{{item.goods_cate_name}}</text>
					</view>
				</view>
			</view>
		</scroll-view>
		
		<view class="brand" v-for="(item, index) in currentList" :key="item.id">
			<view class="header" @click="openList(item)">
				<image class="bg" :src="item.goods_cate_ico" mode="aspectFill" :style="{height: item.goods.length ? '320rpx':'100%'}"></image>
				<view class="info">
					<view class="detail">
						<image class="logo" :src="item.goods_cate_image" mode="aspectFill"></image>
						<view class="right">
							<text class="name">{{item.goods_cate_name}}</text>
							<!-- <text class="origin">意大利</text> -->
						</view>
					</view>
					<view class="tag-list" v-if="item.tag">
						<view class="tag" v-for="(tag, index) in item.tags" :key="index">{{tag}}</view>
					</view>
				</view>
			</view>
			<view class="goods">
				<view class="item" v-for="good in item.goods" :key="good.id" @click="openDetail(good)">
					<image class="pic" :src="good.image" mode="aspectFill"></image>
					<text class="name">{{good.name}}</text>
					<text class="price">¥{{good.reduce_rmb}}</text>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				current: -1,
				currentList: [],
				id: -1
			}
		},
		props: {
			list: {
				type: Array,
				default: () => []
			}
		},
		watch:{
			current(val) {
				if(this.id === -1) return this.currentList = this.list
				this.currentList = this.list.filter(v => this.id == v.id)
			}
		},
		mounted() {
			this.currentList = this.list
		},
		methods: {
			chooseBrand(i,id){
				this.current = i
				this.id = id
			},
			openList(item) {
				uni.navigateTo({
					url: `/pages/third/third?type=normal&id=${item.id}&name=${item.goods_cate_name}`
				})
			},
			openDetail(item) {
				uni.navigateTo({
					url: "/pages/goodsDetails/goodsDetails?id=" + item.id,
				});
			}
		}

	}
</script>

<style scoped lang="scss">
	.brand-list {
		width: 100%;
		.select{
			width: 95%;
			height: 118rpx;
			background: #EEEFF0;
			// padding: 0 10rpx;
			margin: 0 auto;
			.select-list{
				width: 152rpx;
				height: 118rpx;
				background: #FEFFFF;
				margin: 0 10rpx;
				font-size: 22rpx;
				font-weight: 600;
				justify-content: center;
				align-items: center;
				flex-wrap: wrap;
				text{
					margin: 0 30rpx;
				}
			}
			.select-content>view:last-child{
				margin: 0;
			}
		}
		.brand {
			width: 95%;
			margin-bottom: 20rpx;
			background-color: #fff;
			margin: 20rpx auto;
			border-radius: 5rpx;
			position: relative;
			.header {
				width: 100%;
				height: 320rpx;

				.bg {
					width: 100%;
					// height: 320rpx;
					position: absolute;
					left: 0;
					top: 0;
					border-radius: 5rpx 5rpx 0 0;
				}

				.tag-list {
					display: flex;
					margin: 12rpx 0;

					.tag {
						margin-right: 10rpx;
						padding: 5rpx 4rpx;
						border: 1px solid #FFE3C2;
						color: #FFE3C2;
						font-size: 22rpx;
					}
				}

				.info {
					position: relative;
					padding: 20rpx;
					box-sizing: border-box;
					color: #fff;

					.detail {
						display: flex;
						align-items: center;

						.logo {
							width: 92rpx;
							height: 92rpx;
							border-radius: 5rpx;
						}

						.right {
							display: flex;
							flex-direction: column;
							margin-left: 20rpx;

							.name {
								font-size: 36rpx;
								font-weight: bold;
							}

							.origin {
								font-size: 24rpx
							}
						}

						;
					}
				}
			}

			.goods {
				display: flex;
				align-items: center;
				justify-content: space-between;
				position: relative;
				margin-top: -130rpx;
				box-sizing: border-box;
				padding: 0 30rpx;
				padding-bottom: 50rpx;

				.item {
					background-color: #fff;
					width: 210rpx;
					display: flex;
					flex-direction: column;
					align-items: center;
					padding: 20rpx 20rpx 0 20rpx;
					border-radius: 5rpx;

					.pic {
						width: 100%;
						height: 164rpx;
					}

					.name {
						font-size: 24rpx;
						@extend .text-hidden-2;
						margin-top: 41rpx;
						margin-bottom: 30rpx;
					}

					.price {
						text-align: left;
						display: inline-block;
						width: 100%;
						font-size: 36rpx;
						font-weight: bold;
					}
				}
			}
		}
	}
</style>
